#include <cstdio>

int main( )
{
    __int64 n;
    while ( scanf("%I64d", &n) != EOF )
    {
        n = n * ( n + 1 ) / 2;
        n %= 10000;
        n *= n;
        n %= 10000;
        printf("%04I64d\n", n);
    }
}
